package com.shenmazong.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @program: server-java-demo
 * @description: CountDownLatchDemo
 * @author: 亮子说编程
 * @create: 2020-11-12 15:24
 **/
public class CountDownLatchDemo {
    public static CountDownLatch countDownLatch = new CountDownLatch(5);

    public static void main(String[] args) throws InterruptedException {


        for (int i = 0; i < 4; i++) {
            new Thread(()->{
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                CountDownLatchDemo.countDownLatch.countDown();
            }).start();
        }

        System.out.println("等待起飞.....");
        CountDownLatchDemo.countDownLatch.await();

        System.out.println("起飞。。。。");
    }
}
